package com.gtw.modules.sys.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.gtw.common.utils.PageUtils;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.entity.TbCommissionRatio;
import com.gtw.modules.sys.service.SysCommissionRatioService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 抽佣比例
 * 
 * @author wuye
 * @email www.baidu.com
 * @date 2018-04-03 17:45:17
 */
@RestController
@RequestMapping("/sys/commissionratio")
public class SysCommissionRatioController extends AbstractController {
	@Autowired
	private SysCommissionRatioService commissionRatioService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:commissionratio:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TbCommissionRatio> commissionRatioList = commissionRatioService.queryList(query);

		int total = commissionRatioService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(commissionRatioList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:commissionratio:info")
	public R info(@PathVariable("id") Integer id){
		TbCommissionRatio commissionRatio = commissionRatioService.queryObject(id);
		commissionRatio.setRatio(commissionRatio.getRatio()*100);
		commissionRatio.setSecondratio(commissionRatio.getSecondratio()*100);
		commissionRatio.setThirdratio(commissionRatio.getThirdratio()*100);
		commissionRatio.setFourthratio(commissionRatio.getFourthratio()*100);
		return R.ok().put("commissionRatio", commissionRatio);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sys:commissionratio:save")
	public R save(@RequestBody TbCommissionRatio commissionRatio){
		commissionRatio.setRatio(commissionRatio.getRatio()/100);
		commissionRatio.setSecondratio(commissionRatio.getSecondratio()/100);
		commissionRatio.setThirdratio(commissionRatio.getThirdratio()/100);
		commissionRatio.setFourthratio(commissionRatio.getFourthratio()/100);
		commissionRatio.setCreatedate(new Date());
		commissionRatio.setCreateuser(getUser().getUsername());
		commissionRatio.setUpdatedate(new Date());
		commissionRatio.setUpdateuser(getUser().getUsername());
		commissionRatioService.save(commissionRatio);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sys:commissionratio:update")
	public R update(@RequestBody TbCommissionRatio commissionRatio){
		commissionRatio.setRatio(commissionRatio.getRatio()/100);
		commissionRatio.setSecondratio(commissionRatio.getSecondratio()/100);
		commissionRatio.setThirdratio(commissionRatio.getThirdratio()/100);
		commissionRatio.setFourthratio(commissionRatio.getFourthratio()/100);
		commissionRatio.setUpdatedate(new Date());
		commissionRatio.setUpdateuser(getUser().getUsername());
		commissionRatioService.update(commissionRatio);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sys:commissionratio:delete")
	public R delete(@RequestBody Integer[] ids){
		commissionRatioService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
